package main

import (
	"os"
	"fmt"
	"go-glue.googlecode.com/hg/rlglue"
)

func main() {
	var err os.Error
	defer func() {
		if err != nil {
			panic(err)
		}
	}()
	gt := &GlueTester{"test_empty", 0, 0}
	ex := new(rlglue.Experiment)
	if err = ex.AutoConnect(); err != nil {
		return
	}
	if _, err = ex.Init(); err != nil {
		return
	}
	for _, whichEpisode := range []int{1, 2, 3, 4, 5} {
		var obs rlglue.Observation
		var act rlglue.Action
		var r float64
		var t bool
		if obs, act, err = ex.Start(); err != nil {
			return
		}
		if whichEpisode%2 == 0 {
			gt.check(len(act.Ints()) != 0)
			gt.check(len(act.Doubles()) != 0)
			gt.check(len(act.Chars()) != 0)
			gt.check(len(obs.Ints()) != 0)
			gt.check(len(obs.Doubles()) != 0)
			gt.check(len(obs.Chars()) != 0)
		} else {
			gt.check(len(act.Ints()) != 7)
			gt.check(len(act.Doubles()) != 3)
			gt.check(len(act.Chars()) != 1)
			gt.check(len(obs.Ints()) != 2)
			gt.check(len(obs.Doubles()) != 4)
			gt.check(len(obs.Chars()) != 5)
		}
		for _ = range []int{0, 1, 2, 3, 4, 5} {
			if obs, act, r, t, err = ex.Step(); err != nil {
				return
			}
			gt.check(t != false)
			gt.check(r != 0)
			if whichEpisode%2 == 0 {
				gt.check(len(act.Ints()) != 0)
				gt.check(len(act.Doubles()) != 0)
				gt.check(len(act.Chars()) != 0)
				gt.check(len(obs.Ints()) != 0)
				gt.check(len(obs.Doubles()) != 0)
				gt.check(len(obs.Chars()) != 0)
			} else {
				gt.check(len(act.Ints()) != 7)
				gt.check(len(act.Doubles()) != 3)
				gt.check(len(act.Chars()) != 1)
				gt.check(len(obs.Ints()) != 2)
				gt.check(len(obs.Doubles()) != 4)
				gt.check(len(obs.Chars()) != 5)
			}
		}
	}
	if err = ex.Cleanup(); err != nil {
		return
	}
	if err = ex.Close(); err != nil {
		return
	}
	fmt.Printf("%v\n", gt)
	os.Exit(gt.failCount)
}
